package com.xxx.video.dynamic.adapters;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.xxx.video.R;
import com.xxx.video.commen.adapters.BaseRecycleViewAdapter;
import com.xxx.video.commen.adapters.BaseViewHolder;
import com.xxx.video.commen.utils.ResourcesUtils;
import com.xxx.video.commen.utils.StringUtils;
import com.xxx.video.dynamic.beans.FriendListBean;

import butterknife.BindView;

public class PeopleNearbyVerticalListAdapter extends BaseRecycleViewAdapter<FriendListBean.PageBean.ListBean, PeopleNearbyVerticalListAdapter.MyHolder> {


    public PeopleNearbyVerticalListAdapter(@NonNull Context context) {
        super(context);
    }

    @Override
    public MyHolder onCreateDefaultViewHolder(View view, int viewType) {
        return new MyHolder(view);
    }

    @Override
    public int getItemLayout(int viewType) {
        return R.layout.item_people_nearby_vertical_list;
    }

    public void addFriendSuccess(int position) {
        data.get(position).fStatus="0";
        notifyDataSetChanged();
    }


    class MyHolder extends BaseViewHolder {

        @BindView(R.id.iv_item_people_nearby_vertical_list_avatar)
        ImageView ivItemPeopleNearbyVerticalListAvatar;
        @BindView(R.id.tv_item_people_nearby_vertical_list_name)
        TextView tvItemPeopleNearbyVerticalListName;
        @BindView(R.id.tv_item_people_nearby_vertical_list_add)
        TextView tvItemPeopleNearbyVerticalListAdd;
        @BindView(R.id.tv_item_people_nearby_vertical_list_status)
        TextView tvItemPeopleNearbyVerticalListStatus;
        public MyHolder(View itemView) {
            super(itemView);
        }

        @Override
        public void setData2View(int position) {
            FriendListBean.PageBean.ListBean listBean = getItem(position);
            /*
             * avatar
             */
            Glide.with(context).load(ResourcesUtils.getInstance().getImagePath(listBean.picUrl))
                    .apply(new RequestOptions().circleCrop()
                            .placeholder(R.drawable.icon_default_avatar)
                            .error(R.drawable.icon_default_avatar)
                    ).into(ivItemPeopleNearbyVerticalListAvatar);
            /*
             * name
             */
            tvItemPeopleNearbyVerticalListName.setText(StringUtils.getInstance().getNotEmptyMsg(listBean.username));
            tvItemPeopleNearbyVerticalListStatus.setVisibility(View.GONE);
            tvItemPeopleNearbyVerticalListAdd.setVisibility(View.GONE);
            if (listBean.fStatus == null) {
                tvItemPeopleNearbyVerticalListAdd.setVisibility(View.VISIBLE);
            } else if (listBean.fStatus.equals("1")) {
                tvItemPeopleNearbyVerticalListStatus.setVisibility(View.VISIBLE);
                tvItemPeopleNearbyVerticalListStatus.setText(StringUtils.getInstance().getString(R.string.item_friend_alreaady));
            } else if (listBean.fStatus.equals("0")) {
                tvItemPeopleNearbyVerticalListStatus.setVisibility(View.VISIBLE);
                tvItemPeopleNearbyVerticalListStatus.setText(StringUtils.getInstance().getString(R.string.item_friend_request_ing));
            }
            tvItemPeopleNearbyVerticalListAdd.setOnClickListener(v -> {
                if (onItemClickListener != null) {
                    onItemClickListener.onItemClick(listBean, position, 1);
                }
            });
        }
    }
}
